from flask import Flask,Response,request,session


app=Flask(__name__)

#配置session密码
app.config['SECRET_KEY']='123456'

@app.route('/set_cookie')
def set_cookie():
    response=Response('cookie 设置')
    response.set_cookie('user_id','xxx')
    return response

#获取cookie
@app.route('/get_cookie')
def get_cookie():
    user_id=request.cookies.get("user_id")
    print("user_id:",user_id)
    return "获取cookie"

#设置session
@app.route('/set_session')
def set_session():
    #在flask中，session是先把数据经过加密，然后用session_id为key，存放到cookie
    #因为session会经过加密再存储到cookie当中，所以敏感信息会存放到session中
    session['username']='mql'
    return "session设置成功"

#获取session
@app.route('/get_session')
def get_session():
    username=session.get('username')
    print('username:',username)
    return 'get_session 获取成功'



@app.route('/')
def mql():
    return 'hello word'




#配置蓝图
#app.register_blueprint(book_bp)
#app.register_blueprint(course_bp)

if __name__=='__main__':
    app.run(debug=True)